﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using BLL;

namespace WebUI.Pages
{
    public partial class editSLA : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UserController usrController = new UserController();
            int idUsuario = usrController.GetUserID(User.Identity.Name);
            int idTeam = usrController.GetUserTeamID(idUsuario);

            if (idTeam != 9)
            {
                Response.Redirect("../Pages/403.aspx");
            }
            
            if (!Page.IsPostBack)
            {
                int idSla = Convert.ToInt32(Request.QueryString["id"]);
                SlaController slacontroller = new SlaController();
                DataTable dt = slacontroller.GetSLA(idSla);
                DataRow dr = dt.Rows[0];

                string idSLA = dr[0].ToString();
                string SLA = dr[1].ToString();
                string prioridade = dr[2].ToString();
                string TempoResposta = dr[3].ToString();
                string TempoSolucao = dr[4].ToString();

                lblidSLA.Text = idSLA;
                txtSLA.Text = SLA;
                txtPrioridade.Text = prioridade;
                txtTempoResposta.Text = TempoResposta;
                txtTempoSolucao.Text = TempoSolucao;
            }
        }

        protected void cmdSalva_Click(object sender, EventArgs e)
        {
            SlaController slacontroller = new SlaController();
            int idSla = Convert.ToInt32(Request.QueryString["id"]);

            slacontroller.UpdSLA(idSla,txtSLA.Text, txtPrioridade.Text, Convert.ToInt32(txtTempoResposta.Text), Convert.ToInt32(txtTempoSolucao.Text));
            lblMsg.Text = "SLA Alterado com Sucesso.";
        }
    }
}